unit Utils;

interface

uses Windows, Classes;

//procedure Split (const Delimiter: Char; Input: string; const Strings: TStrings);
function Split(valor, caracter: string; index: integer): string;

implementation

{procedure Split (const Delimiter: Char; Input: string; const Strings: TStrings);
begin
   Assert(Assigned(Strings)) ;
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;}

function Split(valor, caracter: string; index: integer): string;
var
anterior,i,contador:integer;
begin
contador:=0;
for i:=0 to length(valor) do
begin
  if valor[i]=caracter then
  begin
  if (contador = index-1) then
  begin
  result:=copy(valor,anterior+1,i-anterior-1);
  exit;
  end;
  anterior:=i;
  inc(contador,1);
  end;

  if i=length(valor) then
  begin
  result:=copy(valor,anterior+1,i-anterior);
  exit;
  end;

  if index=1 then
  begin
  result:=copy(valor,0,pos(caracter,valor)-1);
  exit;
  end;
end;
end;

end.
